/*
 * 
 * 
 * 
 */
package com.hboxs.asl.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.hboxs.asl.util.DateUtils;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Entity - 提现
 */
@Entity
@Table(name = "xx_withdrawal")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_withdrawal_sequence")
public class Withdrawal extends BaseEntity {

    private static final long serialVersionUID = 1475172222701585482L;

    private Member member;

    private BigDecimal point;


    /**
     * 促销类型
     */
    public enum Status {

        // 申请中
        reviewing,

        // 已提现
        done,

        // 拒绝
        reject;


        private static Map<String, Withdrawal.Status> map = new HashMap<>();

        static {
            map.put("申请中", reviewing);
            map.put("已提现", done);
            map.put("拒绝", reject);
        }

        @JsonCreator
        public static Withdrawal.Status forValue(String value) {
            return map.get(value);
        }

        @JsonValue
        public String toValue() {
            for (Map.Entry<String, Withdrawal.Status> entry : map.entrySet()) {
                if (entry.getValue() == this) {
                    return entry.getKey();
                }
            }

            return "";
        }
    }

    private Status status;

    // 银行卡
    private String bankCardNo;

    // 持卡人
    private String bankCardName;

    // 开户行
    private String bankCardSubBranch;

    // 拒绝原因
    private String rejectReason;

    @ManyToOne(fetch = FetchType.LAZY)
    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }

    public BigDecimal getPoint() {
        return point;
    }

    public void setPoint(BigDecimal point) {
        this.point = point;
    }

    public Withdrawal.Status getStatus() {
        return status;
    }

    public void setStatus(Withdrawal.Status status) {
        this.status = status;
    }
    public String getBankCardNo() {
        return bankCardNo;
    }

    public void setBankCardNo(String bankCardNo) {
        this.bankCardNo = bankCardNo;
    }

    public String getBankCardName() {
        return bankCardName;
    }

    public void setBankCardName(String bankCardName) {
        this.bankCardName = bankCardName;
    }

    public String getBankCardSubBranch() {
        return bankCardSubBranch;
    }

    public void setBankCardSubBranch(String bankCardSubBranch) {
        this.bankCardSubBranch = bankCardSubBranch;
    }

    public String getRejectReason() {
        return rejectReason;
    }

    public void setRejectReason(String rejectReason) {
        this.rejectReason = rejectReason;
    }

    @Transient
    public String getCreateDateF(){
        return DateUtils.dateToStr(super.getCreateDate());
    }
}